package com.zdxlz.fcmp.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdxlz.fcmp.business.entity.TaskEntity;
import com.zdxlz.fcmp.business.mapper.TaskMapper;
import com.zdxlz.fcmp.business.service.ITaskService;
import com.zdxlz.fcmp.common.mybatis.enums.HandleStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 任务表服务实现类
 * </p>
 *
 * @author: aman
 * @since 2025-02-08
 */
@Slf4j
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, TaskEntity> implements ITaskService {

    @Override
    public List<TaskEntity> getPendingTask() {
        LambdaQueryWrapper<TaskEntity> queryVpnWrapper = new LambdaQueryWrapper<>();
        queryVpnWrapper
                .in(TaskEntity::getStatus, List.of(HandleStatusEnum.CREATE.getCode(), HandleStatusEnum.FAILED.getCode()))
                .lt(TaskEntity::getRetryCount,3)
        ;
        Page<TaskEntity> page = new Page<>();
        page.setSize(100);
        return this.list(page, queryVpnWrapper);
    }
}
